/**
 * Copyright (C), 2021-2023, 四信物联网有限公司
 * FileName: BDicpMessageHandler
 * Author:   Chapin
 * Date:     2023/10/20 17:53
 * Description: ICP消息处理
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.fourfaith.iot.beidou.handler;

import com.fourfaith.iot.beidou.decodec.BeiDouContants;
import com.fourfaith.iot.beidou.message.inbound.BDicpMessage;
import com.fourfaith.iot.beidou.session.SessionFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 〈ICP消息处理〉
 * @author Chapin
 * @create 2023/10/20
 * @since 1.0.0
 */
@Slf4j
@ChannelHandler.Sharable
public class BDicpMessageHandler extends SimpleChannelInboundHandler<BDicpMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, BDicpMessage msg) throws Exception {
        // ICP消息保存本机卡号
        String localId = msg.getLocalId();
        SessionFactory.getSession().setAttribute(ctx.channel(), BeiDouContants.SENDER_NUMBER,localId);
        SessionFactory.getSession().setAttribute(ctx.channel(), BeiDouContants.FREQUENCY,msg.getRdssFrequentness());
        log.info("session存在本地卡号：{}", localId);

    }
}